package com.mylock;

import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;

import java.io.IOException;
import java.util.List;
import java.util.concurrent.CountDownLatch;

/**
 * @author:wesley
 */
public class ZKTest {


    private static  CountDownLatch cd = new CountDownLatch(1);


    public static void main(String[] args) throws IOException, KeeperException, InterruptedException {

        String rootNode1 = "/disGroup";
        String rootNode2 = "/disLocks";




        ZooKeeper zooKeeper = new ZooKeeper("192.168.56.132:2181", 10000, new Watcher() {
            public void process(WatchedEvent watchedEvent) {
                if (watchedEvent.getState() == Event.KeeperState.SyncConnected) {
                    System.out.println("连接成功....");
                    cd.countDown();
                }
            }
        });


        cd.await();

        List<String> childrens = zooKeeper.getChildren(rootNode2, false);
        System.out.println("共有子节点："+childrens.size());

        for (String children : childrens) {
            zooKeeper.delete(rootNode2+children, -1);
        }

        zooKeeper.close();


    }





}
